<include file="Public/header" title="{$name}" keywords="{$seo_keywords}" description="{$seo_description}" />

	<!-- bootstrap-star-rating
	<link rel="stylesheet" href="__TMPL__Public/assets/plugins/bootstrap-star-rating/css/star-rating.min.css" />
	<script src="__TMPL__Public/assets/plugins/bootstrap-star-rating/js/star-rating.min.js"></script> -->

	<!-- MAIN -->
	<main class="content-wrapper page-book-list">
		<section class="x-box bg-transparent">
			<div class="x-box-body">
				<!-- x-plain-list -->
				<ul class="x-row x-plain-list with-item-padding">
					<content id="vo" table-name="borrow" where="customer_id=$customer['id'] and status!=-1" order="id desc" with-page="true" page-size="10" page-tpl="{first}{prev}{next}{last}" page-setting-mode="1">
               		<li class="x-col-12-12">
						<section class="x-box with-border pre-form">			
							<div class="x-box-header post-header with-border">
								<php>$typeArray = ['<span class="x-badge bg-orange">待确认</span>', '<span class="x-badge bg-green">正在借阅</span>', '<span class="x-badge bg-gray">借阅完成</span>', '<span class="x-badge bg-gray">已取消</span>'];$index=$vo.type</php>
								<div><a href="{:U('Wechat/Index/show')}?id={$vo.book_id}">{$vo.book_name|msubstr=0,15}</a><span class="x-pull-right">{$typeArray[$vo['status']]}</span></div>
							</div>
							<div class="x-box-body">
								<ul class="x-row x-list-value">
									<li class="x-col-12-12">
										<div class="x-row">
											<label class="x-col-2-12">订单号</label>
											<span class="x-col-10-12">{$vo.order_sn}</span>
										</div>
									</li>
									<li class="x-col-12-12">
										<div class="x-row">
											<label class="x-col-2-12">借阅时间</label>
											<span class="x-col-10-12">{$vo.add_time}</span>
										</div>
									</li>
									<li class="x-col-12-12">
										<div class="x-row">
											<label class="x-col-2-12">价格</label>
											<span class="x-col-10-12">¥{$vo.reg_order_price}</span>
										</div>
									</li>
									<li class="x-col-12-12">
										<div class="x-row">
											<label class="x-col-2-12">期别</label>
											<span class="x-col-10-12">{$vo.code_name}</span>
										</div>
									</li>
									<li class="x-col-12-12">
										<div class="x-row">
											<label class="x-col-2-12">人数</label>
											<span class="x-col-10-12">{$vo.code_count}</span>
										</div>
									</li>
								</ul>
							</div>
							<div class="x-box-footer with-border x-p-10 text-right">
			            		<if condition="$vo.status == 0">
								<a class="button button-highlight button-rounded button-small button-border button-p-10" href="javascript:" onclick="cancelBorrowFunc('{$vo.order_sn}');">取消借阅</a>
								</if>
							</div>
						</section>
               		</li>
					</content>
				</ul>
				<div class="paginator">
					<ul class="pagination">
						{$pagination}
					</ul>
				</div>
			</div>
		</section>
	</main>
	<!-- /MAIN -->

<script type="text/javascript">
(function() {
	// initialize star-rating
//	$("#score").rating();
})();

function getBorrowDetailFunc(id) {
	xpop.toast({
	    type: 'warning',
		msg: '待开发中',
	    delay: 1000,
	});
}

function refundBorrowFunc(order_sn) {
	var url = "{:U('Borrow/Index/refund')}";
   	xpop({
       	title: '确认',
        msg: '确认退款？',
        buttons: [{
            text: '取消',
            'class': 'weui_btn_dialog default',
            handler: function ($this) {
        		$this.destroy();
            }
        }, {
            text: '确定',
            'class': 'weui_btn_dialog primary',
            handler: function ($this) {
        		$this.destroy();
                var xloading = xpopup.loading();
				
        		$.ajax({
    				type: 'POST',
    				url : url,
    				data: {out_trade_no : order_sn},
    				dataType: 'json',
    				async : false,
    				success: function(data) {
    		        	xloading.destroy();
    		        	
    					if (data.code == 0) {
    	    		   		xpop.toast({
    	    		   		    type: 'success',
    	    		   	        msg: data.msg,
    	    		   	        delay: 1000,
    	    		   	        afterClose: function() {
    	    		        	//	window.location.reload();
    	    		   	        }
    	    		   	    });
    					} else {
    						xpop.toast({
    						    type: 'error',
    	    		   	        msg: data.msg,
    					        delay: 1000,
    					    });
    					}
    				}
    			});
            }
        }]
    });
}

function delelteBorrowFunc(id) {
	var url = "{:U('Borrow/Index/deleteBorrow')}?id=" + id;
   	xpop({
       	title: '确认',
        msg: '确认删除？',
        buttons: [{
            text: '取消',
            'class': 'weui_btn_dialog default',
            handler: function ($this) {
        		$this.destroy();
            }
        }, {
            text: '确定',
            'class': 'weui_btn_dialog primary',
            handler: function ($this) {
        		$this.destroy();
                var xloading = xpopup.loading();
				
        		$.ajax({
    				type: 'DELETE',
    				url : url,
    				dataType: 'json',
    				async : false,
    				success: function(data) {
    		        	xloading.destroy();
    		        	
    					if (data.code == 0) {
    	    		   		xpop.toast({
    	    		   		    type: 'success',
    	    		   	        msg: data.msg,
    	    		   	        delay: 1000,
    	    		   	        afterClose: function() {
    	    		        		window.location.reload();
    	    		   	        }
    	    		   	    });
    					} else {
    						xpop.toast({
    						    type: 'error',
    	    		   	        msg: data.msg,
    					        delay: 1000,
    					    });
    					}
    				}
    			});
            }
        }]
    });
}
</script>

<include file="Public/footer" />
